package zsf.java.proxy.cglib;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
/**
 * Author: zsf
 * CreateDate: 14-1-10 下午2:32
 */
public class BookFacadeCglib   implements   MethodInterceptor{
    private Object target;
    public Object getInstance(Object target)
    {
         this.target=target;
        Enhancer enhancer=new Enhancer();
        enhancer.setSuperclass(this.target.getClass());
        enhancer.setCallback(this);

        return enhancer.create();
    }


    @Override
    public Object intercept(Object obj,Method method,Object[] args,MethodProxy proxy)throws  Throwable
    {
        System.out.println("事物开始：");
        proxy.invokeSuper(obj,args) ;
        System.out.println("事物结束");
        return  null;
    }
}
